/*
 * 
 */
package p1;

import java.io.IOException;

/**
 *
 * @author Derek Ward
 */
public class P1 
{
    static      private     InterpretArgs       ia;
    static      private     Graph               graph;
    static      private     ProblemFile         pf;
    static      private     DataFileUnitTest    dfut;
    static      private     ProblemFileUnitTest pfut;
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
//        dfut = new DataFileUnitTest("datafile");
//        
//        dfut.execute();
        
//        pfut = new ProblemFileUnitTest("problemfile");
//        
//        pfut.execute();
        
        
        // Grab arguments from command line, check for sane 
        // inputs 
        try
        {
            ia = new InterpretArgs(args);
        }
        catch (IllegalArgumentException ex)
        {
            System.err.println(ex.getMessage());
            printUsage();
            System.exit(1);
        }
        
        // Create a new Graph object by passing it a newly
        // created DataFile object. 
        try 
        {
            graph = new Graph(new DataFile(ia.getDataFileName()));
//            graph = new Graph(new DataFile("datafile"));
        } 
        catch (IOException ex) 
        {
            System.err.println(ex.getMessage());
            printUsage();
            System.exit(1);
        } 
        catch (InvalidEdgeWeightException ex) 
        {
            System.err.println(ex.getMessage());
            printUsage();
            System.exit(1);
        }
        
//        graph.printGraph();
        
        
        // Check to see if a program file was passed in
        // as an argument.  If not enter interactive
        // mode.
        if ( ia.getInteractiveModeSetting() )
            pf = new ProblemFile(graph);
        else
            pf = new ProblemFile(graph, ia.getProblemFileName());
        
//        if ( true )
//            pf = new ProblemFile(graph);
//        else
//            pf = new ProblemFile(graph, "problemfile");
        
        
        // Read the problem file from file or command line
        // and find solutions to the problems
        try {
            pf.readProblemFile();
        } catch (IOException ex) {
            System.err.println(ex.getMessage());
            System.exit(1);
        } catch (InvalidProblemException ex) {
            System.err.println(ex.getMessage());
            System.exit(1);
        }
        
    }
    
    public static void printUsage()
    {
        System.out.println("Usage:  run datafile [problemfile]");
    }
}
